#pragma once
#include <sys/epoll.h>
#include "Epoll.h"
#include "Socket.h"
#include "InetAddress.h"
#include"EventLoop.h"
#include <functional>
#include"Connection.h"

class Epoll;
class EventLoop;
class Channel
{
public:
    using func_t = std::function<void()>;

public:
    Channel(EventLoop *loop, int fd);
    ~Channel();

    int fd();
    void useet();
    void enablereading();
    void setinepoll();
    void setrevents(uint32_t ev);
    bool inepoll();
    uint32_t events();
    uint32_t revents();
    // void newConnection(Socket *servsock);
    void onmessage();

    void handleevent();

    void setreadcallback(func_t fn);

private:
    int fd_ = -1 ; 
    bool inepoll_ ;
    EventLoop *loop_=nullptr; 
    uint32_t events_ = 0;  // fd_需要监视的事件。listenfd和clientfd需要监视EPOLLIN，clientfd还可能需要监视EPOLLOUT。
    uint32_t revents_ = 0; // fd_已发生的事件。
    func_t readCallBack_;
};